package cs2340.spring13.team3.wheresmystuff.views;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import cs2340.spring13.team3.wheresmystuff.R;
import cs2340.spring13.team3.wheresmystuff.model.Item;
import cs2340.spring13.team3.wheresmystuff.model.User;
import cs2340.spring13.team3.wheresmystuff.presenters.LoginManager;

public class ViewFoundItemsActivity extends Activity {

	private User currentUser;
	private List<String> foundItemNames;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_view_found_items);
		ListView lv = (ListView) findViewById(R.id.foundItemList);

		currentUser = LoginManager.getInstance().getUser();
		System.out.println("my name in view found:" + currentUser.getName());
		List<Item> foundItems = currentUser.getItems();
		foundItemNames = new ArrayList<String>();

		for (Item item : foundItems) {
			if (item.getFound()) {
				foundItemNames.add(item.getName());
				System.out.println(item.getName());
			}
		}

		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, foundItemNames);
		lv.setAdapter(adapter);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.view_found_items, menu);
		return true;

	}

	/**
	 * Starts the addItemActivity when the user clicks the "add more" button.
	 * 
	 * @param view
	 */
	public void onAddClick(View view) {
		Intent intent = new Intent(this, AddItemActivity.class);
		startActivity(intent);
	}
}
